package qldc.pm.tiensu.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.util.PortalUtil;

import qldc.pm.tiensu.service.ClpSerializer;
import qldc.pm.tiensu.service.TangThuLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Method;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class TangThuClp extends BaseModelImpl<TangThu> implements TangThu {
    private long _tangThuId;
    private long _userId;
    private String _userUuid;
    private String _userName;
    private Date _createDate;
    private Date _modifiedDate;
    private String _soSoHoKhau;
    private String _diaChiThuongTru;
    private long _diaChiThuongTruTinhId;
    private long _diaChiThuongTruQuanHuyenId;
    private long _diaChiThuongTruPhuongXaId;
    private long _doiTuongTienSuId;
    private String _hoVaTenNguoiCoTienSu;
    private Date _ngayLuu;
    private String _viTriLuu;
    private boolean _lapMoi;
    private String _chuThich;
    private BaseModel<?> _tangThuRemoteModel;

    public TangThuClp() {
    }

    @Override
    public Class<?> getModelClass() {
        return TangThu.class;
    }

    @Override
    public String getModelClassName() {
        return TangThu.class.getName();
    }

    @Override
    public long getPrimaryKey() {
        return _tangThuId;
    }

    @Override
    public void setPrimaryKey(long primaryKey) {
        setTangThuId(primaryKey);
    }

    @Override
    public Serializable getPrimaryKeyObj() {
        return _tangThuId;
    }

    @Override
    public void setPrimaryKeyObj(Serializable primaryKeyObj) {
        setPrimaryKey(((Long) primaryKeyObj).longValue());
    }

    @Override
    public Map<String, Object> getModelAttributes() {
        Map<String, Object> attributes = new HashMap<String, Object>();

        attributes.put("tangThuId", getTangThuId());
        attributes.put("userId", getUserId());
        attributes.put("userName", getUserName());
        attributes.put("createDate", getCreateDate());
        attributes.put("modifiedDate", getModifiedDate());
        attributes.put("soSoHoKhau", getSoSoHoKhau());
        attributes.put("diaChiThuongTru", getDiaChiThuongTru());
        attributes.put("diaChiThuongTruTinhId", getDiaChiThuongTruTinhId());
        attributes.put("diaChiThuongTruQuanHuyenId",
            getDiaChiThuongTruQuanHuyenId());
        attributes.put("diaChiThuongTruPhuongXaId",
            getDiaChiThuongTruPhuongXaId());
        attributes.put("doiTuongTienSuId", getDoiTuongTienSuId());
        attributes.put("hoVaTenNguoiCoTienSu", getHoVaTenNguoiCoTienSu());
        attributes.put("ngayLuu", getNgayLuu());
        attributes.put("viTriLuu", getViTriLuu());
        attributes.put("lapMoi", getLapMoi());
        attributes.put("chuThich", getChuThich());

        return attributes;
    }

    @Override
    public void setModelAttributes(Map<String, Object> attributes) {
        Long tangThuId = (Long) attributes.get("tangThuId");

        if (tangThuId != null) {
            setTangThuId(tangThuId);
        }

        Long userId = (Long) attributes.get("userId");

        if (userId != null) {
            setUserId(userId);
        }

        String userName = (String) attributes.get("userName");

        if (userName != null) {
            setUserName(userName);
        }

        Date createDate = (Date) attributes.get("createDate");

        if (createDate != null) {
            setCreateDate(createDate);
        }

        Date modifiedDate = (Date) attributes.get("modifiedDate");

        if (modifiedDate != null) {
            setModifiedDate(modifiedDate);
        }

        String soSoHoKhau = (String) attributes.get("soSoHoKhau");

        if (soSoHoKhau != null) {
            setSoSoHoKhau(soSoHoKhau);
        }

        String diaChiThuongTru = (String) attributes.get("diaChiThuongTru");

        if (diaChiThuongTru != null) {
            setDiaChiThuongTru(diaChiThuongTru);
        }

        Long diaChiThuongTruTinhId = (Long) attributes.get(
                "diaChiThuongTruTinhId");

        if (diaChiThuongTruTinhId != null) {
            setDiaChiThuongTruTinhId(diaChiThuongTruTinhId);
        }

        Long diaChiThuongTruQuanHuyenId = (Long) attributes.get(
                "diaChiThuongTruQuanHuyenId");

        if (diaChiThuongTruQuanHuyenId != null) {
            setDiaChiThuongTruQuanHuyenId(diaChiThuongTruQuanHuyenId);
        }

        Long diaChiThuongTruPhuongXaId = (Long) attributes.get(
                "diaChiThuongTruPhuongXaId");

        if (diaChiThuongTruPhuongXaId != null) {
            setDiaChiThuongTruPhuongXaId(diaChiThuongTruPhuongXaId);
        }

        Long doiTuongTienSuId = (Long) attributes.get("doiTuongTienSuId");

        if (doiTuongTienSuId != null) {
            setDoiTuongTienSuId(doiTuongTienSuId);
        }

        String hoVaTenNguoiCoTienSu = (String) attributes.get(
                "hoVaTenNguoiCoTienSu");

        if (hoVaTenNguoiCoTienSu != null) {
            setHoVaTenNguoiCoTienSu(hoVaTenNguoiCoTienSu);
        }

        Date ngayLuu = (Date) attributes.get("ngayLuu");

        if (ngayLuu != null) {
            setNgayLuu(ngayLuu);
        }

        String viTriLuu = (String) attributes.get("viTriLuu");

        if (viTriLuu != null) {
            setViTriLuu(viTriLuu);
        }

        Boolean lapMoi = (Boolean) attributes.get("lapMoi");

        if (lapMoi != null) {
            setLapMoi(lapMoi);
        }

        String chuThich = (String) attributes.get("chuThich");

        if (chuThich != null) {
            setChuThich(chuThich);
        }
    }

    @Override
    public long getTangThuId() {
        return _tangThuId;
    }

    @Override
    public void setTangThuId(long tangThuId) {
        _tangThuId = tangThuId;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setTangThuId", long.class);

                method.invoke(_tangThuRemoteModel, tangThuId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public long getUserId() {
        return _userId;
    }

    @Override
    public void setUserId(long userId) {
        _userId = userId;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setUserId", long.class);

                method.invoke(_tangThuRemoteModel, userId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getUserUuid() throws SystemException {
        return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
    }

    @Override
    public void setUserUuid(String userUuid) {
        _userUuid = userUuid;
    }

    @Override
    public String getUserName() {
        return _userName;
    }

    @Override
    public void setUserName(String userName) {
        _userName = userName;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setUserName", String.class);

                method.invoke(_tangThuRemoteModel, userName);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public Date getCreateDate() {
        return _createDate;
    }

    @Override
    public void setCreateDate(Date createDate) {
        _createDate = createDate;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setCreateDate", Date.class);

                method.invoke(_tangThuRemoteModel, createDate);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public Date getModifiedDate() {
        return _modifiedDate;
    }

    @Override
    public void setModifiedDate(Date modifiedDate) {
        _modifiedDate = modifiedDate;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setModifiedDate", Date.class);

                method.invoke(_tangThuRemoteModel, modifiedDate);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getSoSoHoKhau() {
        return _soSoHoKhau;
    }

    @Override
    public void setSoSoHoKhau(String soSoHoKhau) {
        _soSoHoKhau = soSoHoKhau;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setSoSoHoKhau", String.class);

                method.invoke(_tangThuRemoteModel, soSoHoKhau);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getDiaChiThuongTru() {
        return _diaChiThuongTru;
    }

    @Override
    public void setDiaChiThuongTru(String diaChiThuongTru) {
        _diaChiThuongTru = diaChiThuongTru;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setDiaChiThuongTru",
                        String.class);

                method.invoke(_tangThuRemoteModel, diaChiThuongTru);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public long getDiaChiThuongTruTinhId() {
        return _diaChiThuongTruTinhId;
    }

    @Override
    public void setDiaChiThuongTruTinhId(long diaChiThuongTruTinhId) {
        _diaChiThuongTruTinhId = diaChiThuongTruTinhId;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setDiaChiThuongTruTinhId",
                        long.class);

                method.invoke(_tangThuRemoteModel, diaChiThuongTruTinhId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public long getDiaChiThuongTruQuanHuyenId() {
        return _diaChiThuongTruQuanHuyenId;
    }

    @Override
    public void setDiaChiThuongTruQuanHuyenId(long diaChiThuongTruQuanHuyenId) {
        _diaChiThuongTruQuanHuyenId = diaChiThuongTruQuanHuyenId;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setDiaChiThuongTruQuanHuyenId",
                        long.class);

                method.invoke(_tangThuRemoteModel, diaChiThuongTruQuanHuyenId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public long getDiaChiThuongTruPhuongXaId() {
        return _diaChiThuongTruPhuongXaId;
    }

    @Override
    public void setDiaChiThuongTruPhuongXaId(long diaChiThuongTruPhuongXaId) {
        _diaChiThuongTruPhuongXaId = diaChiThuongTruPhuongXaId;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setDiaChiThuongTruPhuongXaId",
                        long.class);

                method.invoke(_tangThuRemoteModel, diaChiThuongTruPhuongXaId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public long getDoiTuongTienSuId() {
        return _doiTuongTienSuId;
    }

    @Override
    public void setDoiTuongTienSuId(long doiTuongTienSuId) {
        _doiTuongTienSuId = doiTuongTienSuId;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setDoiTuongTienSuId",
                        long.class);

                method.invoke(_tangThuRemoteModel, doiTuongTienSuId);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getHoVaTenNguoiCoTienSu() {
        return _hoVaTenNguoiCoTienSu;
    }

    @Override
    public void setHoVaTenNguoiCoTienSu(String hoVaTenNguoiCoTienSu) {
        _hoVaTenNguoiCoTienSu = hoVaTenNguoiCoTienSu;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setHoVaTenNguoiCoTienSu",
                        String.class);

                method.invoke(_tangThuRemoteModel, hoVaTenNguoiCoTienSu);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public Date getNgayLuu() {
        return _ngayLuu;
    }

    @Override
    public void setNgayLuu(Date ngayLuu) {
        _ngayLuu = ngayLuu;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setNgayLuu", Date.class);

                method.invoke(_tangThuRemoteModel, ngayLuu);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getViTriLuu() {
        return _viTriLuu;
    }

    @Override
    public void setViTriLuu(String viTriLuu) {
        _viTriLuu = viTriLuu;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setViTriLuu", String.class);

                method.invoke(_tangThuRemoteModel, viTriLuu);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public boolean getLapMoi() {
        return _lapMoi;
    }

    @Override
    public boolean isLapMoi() {
        return _lapMoi;
    }

    @Override
    public void setLapMoi(boolean lapMoi) {
        _lapMoi = lapMoi;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setLapMoi", boolean.class);

                method.invoke(_tangThuRemoteModel, lapMoi);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    @Override
    public String getChuThich() {
        return _chuThich;
    }

    @Override
    public void setChuThich(String chuThich) {
        _chuThich = chuThich;

        if (_tangThuRemoteModel != null) {
            try {
                Class<?> clazz = _tangThuRemoteModel.getClass();

                Method method = clazz.getMethod("setChuThich", String.class);

                method.invoke(_tangThuRemoteModel, chuThich);
            } catch (Exception e) {
                throw new UnsupportedOperationException(e);
            }
        }
    }

    public BaseModel<?> getTangThuRemoteModel() {
        return _tangThuRemoteModel;
    }

    public void setTangThuRemoteModel(BaseModel<?> tangThuRemoteModel) {
        _tangThuRemoteModel = tangThuRemoteModel;
    }

    public Object invokeOnRemoteModel(String methodName,
        Class<?>[] parameterTypes, Object[] parameterValues)
        throws Exception {
        Object[] remoteParameterValues = new Object[parameterValues.length];

        for (int i = 0; i < parameterValues.length; i++) {
            if (parameterValues[i] != null) {
                remoteParameterValues[i] = ClpSerializer.translateInput(parameterValues[i]);
            }
        }

        Class<?> remoteModelClass = _tangThuRemoteModel.getClass();

        ClassLoader remoteModelClassLoader = remoteModelClass.getClassLoader();

        Class<?>[] remoteParameterTypes = new Class[parameterTypes.length];

        for (int i = 0; i < parameterTypes.length; i++) {
            if (parameterTypes[i].isPrimitive()) {
                remoteParameterTypes[i] = parameterTypes[i];
            } else {
                String parameterTypeName = parameterTypes[i].getName();

                remoteParameterTypes[i] = remoteModelClassLoader.loadClass(parameterTypeName);
            }
        }

        Method method = remoteModelClass.getMethod(methodName,
                remoteParameterTypes);

        Object returnValue = method.invoke(_tangThuRemoteModel,
                remoteParameterValues);

        if (returnValue != null) {
            returnValue = ClpSerializer.translateOutput(returnValue);
        }

        return returnValue;
    }

    @Override
    public void persist() throws SystemException {
        if (this.isNew()) {
            TangThuLocalServiceUtil.addTangThu(this);
        } else {
            TangThuLocalServiceUtil.updateTangThu(this);
        }
    }

    @Override
    public TangThu toEscapedModel() {
        return (TangThu) ProxyUtil.newProxyInstance(TangThu.class.getClassLoader(),
            new Class[] { TangThu.class }, new AutoEscapeBeanHandler(this));
    }

    @Override
    public Object clone() {
        TangThuClp clone = new TangThuClp();

        clone.setTangThuId(getTangThuId());
        clone.setUserId(getUserId());
        clone.setUserName(getUserName());
        clone.setCreateDate(getCreateDate());
        clone.setModifiedDate(getModifiedDate());
        clone.setSoSoHoKhau(getSoSoHoKhau());
        clone.setDiaChiThuongTru(getDiaChiThuongTru());
        clone.setDiaChiThuongTruTinhId(getDiaChiThuongTruTinhId());
        clone.setDiaChiThuongTruQuanHuyenId(getDiaChiThuongTruQuanHuyenId());
        clone.setDiaChiThuongTruPhuongXaId(getDiaChiThuongTruPhuongXaId());
        clone.setDoiTuongTienSuId(getDoiTuongTienSuId());
        clone.setHoVaTenNguoiCoTienSu(getHoVaTenNguoiCoTienSu());
        clone.setNgayLuu(getNgayLuu());
        clone.setViTriLuu(getViTriLuu());
        clone.setLapMoi(getLapMoi());
        clone.setChuThich(getChuThich());

        return clone;
    }

    @Override
    public int compareTo(TangThu tangThu) {
        int value = 0;

        value = DateUtil.compareTo(getCreateDate(), tangThu.getCreateDate());

        value = value * -1;

        if (value != 0) {
            return value;
        }

        return 0;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof TangThuClp)) {
            return false;
        }

        TangThuClp tangThu = (TangThuClp) obj;

        long primaryKey = tangThu.getPrimaryKey();

        if (getPrimaryKey() == primaryKey) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return (int) getPrimaryKey();
    }

    @Override
    public String toString() {
        StringBundler sb = new StringBundler(33);

        sb.append("{tangThuId=");
        sb.append(getTangThuId());
        sb.append(", userId=");
        sb.append(getUserId());
        sb.append(", userName=");
        sb.append(getUserName());
        sb.append(", createDate=");
        sb.append(getCreateDate());
        sb.append(", modifiedDate=");
        sb.append(getModifiedDate());
        sb.append(", soSoHoKhau=");
        sb.append(getSoSoHoKhau());
        sb.append(", diaChiThuongTru=");
        sb.append(getDiaChiThuongTru());
        sb.append(", diaChiThuongTruTinhId=");
        sb.append(getDiaChiThuongTruTinhId());
        sb.append(", diaChiThuongTruQuanHuyenId=");
        sb.append(getDiaChiThuongTruQuanHuyenId());
        sb.append(", diaChiThuongTruPhuongXaId=");
        sb.append(getDiaChiThuongTruPhuongXaId());
        sb.append(", doiTuongTienSuId=");
        sb.append(getDoiTuongTienSuId());
        sb.append(", hoVaTenNguoiCoTienSu=");
        sb.append(getHoVaTenNguoiCoTienSu());
        sb.append(", ngayLuu=");
        sb.append(getNgayLuu());
        sb.append(", viTriLuu=");
        sb.append(getViTriLuu());
        sb.append(", lapMoi=");
        sb.append(getLapMoi());
        sb.append(", chuThich=");
        sb.append(getChuThich());
        sb.append("}");

        return sb.toString();
    }

    @Override
    public String toXmlString() {
        StringBundler sb = new StringBundler(52);

        sb.append("<model><model-name>");
        sb.append("qldc.pm.tiensu.model.TangThu");
        sb.append("</model-name>");

        sb.append(
            "<column><column-name>tangThuId</column-name><column-value><![CDATA[");
        sb.append(getTangThuId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>userId</column-name><column-value><![CDATA[");
        sb.append(getUserId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>userName</column-name><column-value><![CDATA[");
        sb.append(getUserName());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>createDate</column-name><column-value><![CDATA[");
        sb.append(getCreateDate());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
        sb.append(getModifiedDate());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>soSoHoKhau</column-name><column-value><![CDATA[");
        sb.append(getSoSoHoKhau());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>diaChiThuongTru</column-name><column-value><![CDATA[");
        sb.append(getDiaChiThuongTru());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>diaChiThuongTruTinhId</column-name><column-value><![CDATA[");
        sb.append(getDiaChiThuongTruTinhId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>diaChiThuongTruQuanHuyenId</column-name><column-value><![CDATA[");
        sb.append(getDiaChiThuongTruQuanHuyenId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>diaChiThuongTruPhuongXaId</column-name><column-value><![CDATA[");
        sb.append(getDiaChiThuongTruPhuongXaId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>doiTuongTienSuId</column-name><column-value><![CDATA[");
        sb.append(getDoiTuongTienSuId());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>hoVaTenNguoiCoTienSu</column-name><column-value><![CDATA[");
        sb.append(getHoVaTenNguoiCoTienSu());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>ngayLuu</column-name><column-value><![CDATA[");
        sb.append(getNgayLuu());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>viTriLuu</column-name><column-value><![CDATA[");
        sb.append(getViTriLuu());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>lapMoi</column-name><column-value><![CDATA[");
        sb.append(getLapMoi());
        sb.append("]]></column-value></column>");
        sb.append(
            "<column><column-name>chuThich</column-name><column-value><![CDATA[");
        sb.append(getChuThich());
        sb.append("]]></column-value></column>");

        sb.append("</model>");

        return sb.toString();
    }
}
